/*
 * ErgSettingsWorkLoad.java
 *
 * Created on May 16, 2008, 11:54 AM
 */

package ca.jerg.app;

import java.awt.event.*;
import javax.swing.*;

import ca.jerg.config.*;

/**
 *
 * @author  dave
 */
public class ErgSettingsDescriptions extends javax.swing.JFrame {

	private ErgConfigWorkDetails details;

	
	/**
	 * Get the value of work
	 *
	 * @return the value of work
	 */
	public ErgConfigWorkDetails getDetails()
	{
		return details;
	}

	/**
	 * Set the value of work
	 *
	 * @param work new value of work
	 */
	public void setDetails( ErgConfigWorkDetails details )
	{
		this.details = details;
	}

    /*
     * Set to native Look & Feel
     */
	{
		try 
		{
			javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
		} 
		catch ( Exception e )
		{
			e.printStackTrace();
		}
	}
	
    /** Creates new form ErgSettingsWorkLoad */
    public ErgSettingsDescriptions() {
        details = new ErgConfigWorkDetails();
		initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        anaerobic = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        vo2max = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        threshold = new javax.swing.JTextArea();
        jScrollPane4 = new javax.swing.JScrollPane();
        tempo = new javax.swing.JTextArea();
        jScrollPane5 = new javax.swing.JScrollPane();
        distance = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("jErg - Work Load Descriptions");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 0, 15)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Describe each work load");

        jLabel2.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel2.setText("Work Zone");

        jLabel4.setText("Anaerobic");

        jLabel5.setText("VO2 Max");

        jLabel6.setText("Threshold");

        jLabel7.setText("Tempo");

        jLabel8.setText("Distance");

        jButton1.setText("Don't Save");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Save");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Defaults");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        anaerobic.setColumns(20);
        anaerobic.setLineWrap(true);
        anaerobic.setRows(5);
        anaerobic.setText(details.getString(IErgConfig.KEY_ANAEROBIC,ErgConfigWorkDetails.DEF_ANAEROBIC_DETAILS));
        jScrollPane1.setViewportView(anaerobic);

        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        vo2max.setColumns(20);
        vo2max.setRows(5);
        vo2max.setText(details.getString(IErgConfig.KEY_VO2,ErgConfigWorkDetails.DEF_VO2_DETAILS));
        vo2max.setMinimumSize(new java.awt.Dimension(260, 17));
        jScrollPane2.setViewportView(vo2max);

        jScrollPane3.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        threshold.setColumns(20);
        threshold.setRows(5);
        threshold.setText(details.getString(IErgConfig.KEY_FT,ErgConfigWorkDetails.DEF_FT_DETAILS));
        threshold.setMinimumSize(new java.awt.Dimension(260, 17));
        jScrollPane3.setViewportView(threshold);

        jScrollPane4.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        tempo.setColumns(20);
        tempo.setRows(5);
        tempo.setText(details.getString(IErgConfig.KEY_TEMPO,ErgConfigWorkDetails.DEF_TEMPO_DETAILS));
        tempo.setMinimumSize(new java.awt.Dimension(260, 17));
        jScrollPane4.setViewportView(tempo);

        jScrollPane5.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        distance.setColumns(20);
        distance.setRows(5);
        distance.setText(details.getString(IErgConfig.KEY_DISTANCE,ErgConfigWorkDetails.DEF_DISTANCE_DETAILS));
        distance.setMinimumSize(new java.awt.Dimension(260, 17));
        jScrollPane5.setViewportView(distance);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 578, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 331, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(41, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)
                                .addGap(2, 2, 2))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 461, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(0, 0, 0))
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE))))
                .addContainerGap())
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 578, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 357, Short.MAX_VALUE)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel4)
                        .addGap(29, 29, 29)
                        .addComponent(jLabel5)
                        .addGap(29, 29, 29)
                        .addComponent(jLabel6)
                        .addGap(26, 26, 26)
                        .addComponent(jLabel7))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabel8))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
	// the "Don't Save" button
	dispose();
}//GEN-LAST:event_jButton1ActionPerformed

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
	System.out.println("Closing window...");
}//GEN-LAST:event_formWindowClosed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
	// the "Defaults" button
	details.defaults();
	initializeSliders();
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
	// the "Save" button
	details.put(IErgConfig.KEY_ANAEROBIC,anaerobic.getText());
	details.put(IErgConfig.KEY_VO2,vo2max.getText());
	details.put(IErgConfig.KEY_FT,threshold.getText());
	details.put(IErgConfig.KEY_TEMPO,tempo.getText());
	details.put(IErgConfig.KEY_DISTANCE,distance.getText());
	
	dispose();
}//GEN-LAST:event_jButton2ActionPerformed

protected JRootPane createRootPane() 
{
	ActionListener actionListener = new ActionListener() 
	{
		public void actionPerformed(ActionEvent actionEvent) 
		{
			dispose();
		}
	};

	JRootPane rootPane = new JRootPane();
	KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0);
	rootPane.registerKeyboardAction(actionListener,stroke,JComponent.WHEN_IN_FOCUSED_WINDOW);

	return rootPane;
}
	
private void initializeSliders()
{
	anaerobic.setText(details.getString(IErgConfig.KEY_ANAEROBIC,ErgConfigWorkDetails.DEF_ANAEROBIC_DETAILS));
	vo2max.setText(details.getString(IErgConfig.KEY_VO2,ErgConfigWorkDetails.DEF_VO2_DETAILS));
	threshold.setText(details.getString(IErgConfig.KEY_FT,ErgConfigWorkDetails.DEF_FT_DETAILS));
	tempo.setText(details.getString(IErgConfig.KEY_TEMPO,ErgConfigWorkDetails.DEF_TEMPO_DETAILS));
	distance.setText(details.getString(	IErgConfig.KEY_DISTANCE,ErgConfigWorkDetails.DEF_DISTANCE_DETAILS));
}

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ErgSettingsDescriptions().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea anaerobic;
    private javax.swing.JTextArea distance;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextArea tempo;
    private javax.swing.JTextArea threshold;
    private javax.swing.JTextArea vo2max;
    // End of variables declaration//GEN-END:variables

}
